package com.ruoyi.fun.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fun.domain.EcPayment;
import com.ruoyi.fun.service.IEcPaymentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支付记录Controller
 * 
 * @author ruoyi
 * @date 2025-08-06
 */
@RestController
@RequestMapping("/fun/payment")
public class EcPaymentController extends BaseController
{
    @Autowired
    private IEcPaymentService ecPaymentService;

    /**
     * 查询支付记录列表
     */
    @PreAuthorize("@ss.hasPermi('fun:payment:list')")
    @DataScope(userAlias = "p", permission = "fun:payment:list")
    @GetMapping("/list")
    public TableDataInfo list(EcPayment ecPayment)
    {
        startPage();
        Long orgId = getOrgId();
        // 103组织拥有不过滤的权限
        if (orgId != null && orgId == 103L) {
            orgId = null;
        }
        ecPayment.setOrgId(orgId);
        List<EcPayment> list = ecPaymentService.selectEcPaymentList(ecPayment);
        return getDataTable(list);
    }

    /**
     * 导出支付记录列表
     */
    @PreAuthorize("@ss.hasPermi('fun:payment:export')")
    @DataScope(userAlias = "p", permission = "fun:payment:export")
    @Log(title = "支付记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EcPayment ecPayment)
    {
        List<EcPayment> list = ecPaymentService.selectEcPaymentList(ecPayment);
        ExcelUtil<EcPayment> util = new ExcelUtil<EcPayment>(EcPayment.class);
        util.exportExcel(response, list, "支付记录数据");
    }

    /**
     * 获取支付记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('fun:payment:query')")
    @GetMapping(value = "/{paymentId}")
    public AjaxResult getInfo(@PathVariable("paymentId") Long paymentId)
    {
        Long orgId = getOrgId();
        // 103组织拥有不过滤的权限
        if (orgId != null && orgId == 103L) {
            orgId = null;
        }
        return success(ecPaymentService.selectEcPaymentByPaymentIdAndOrgId(paymentId, orgId));
    }

    /**
     * 新增支付记录
     */
    @PreAuthorize("@ss.hasPermi('fun:payment:add')")
    @Log(title = "支付记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EcPayment ecPayment)
    {
        ecPayment.setOrgId(getOrgId());
        return toAjax(ecPaymentService.insertEcPayment(ecPayment));
    }

    /**
     * 修改支付记录
     */
    @PreAuthorize("@ss.hasPermi('fun:payment:edit')")
    @Log(title = "支付记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EcPayment ecPayment)
    {
        return toAjax(ecPaymentService.updateEcPayment(ecPayment));
    }

    /**
     * 删除支付记录
     */
    @PreAuthorize("@ss.hasPermi('fun:payment:remove')")
    @Log(title = "支付记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paymentIds}")
    public AjaxResult remove(@PathVariable Long[] paymentIds)
    {
        return toAjax(ecPaymentService.deleteEcPaymentByPaymentIds(paymentIds));
    }
    /**
     * 根据paymentId和组织ID获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('fun:ecpayment:query')")
    @GetMapping(value = "/{paymentId}/org/{orgId}")
    public AjaxResult getInfoByOrgId(@PathVariable("paymentId") Long paymentId, @PathVariable("orgId") Long orgId)
    {
        return success(ecPaymentService.selectEcPaymentByPaymentIdAndOrgId(paymentId, orgId));
    }

    /**
     * 根据组织ID查询列表
     */
    @PreAuthorize("@ss.hasPermi('fun:ecpayment:list')")
    @GetMapping("/org/{orgId}")
    public TableDataInfo listByOrgId(@PathVariable Long orgId)
    {
        startPage();
        EcPayment ecPayment = new EcPayment();
        List<EcPayment> list = ecPaymentService.selectEcPaymentListByOrgId(ecPayment, orgId);
        return getDataTable(list);
    }


}